package com.watersys.util;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;


/**
 * 通过百度定位系统得到径维度
 * @author king
 *
 */
public class BaiDuGpsUtil {
	
	
	
	public LocationClient client;
    
	
	public  BDLocation location;
   
    
	public BaiDuGpsUtil(LocationClient client){
		
		this.client=client;
		
	}
	
	/**
	 * 创建定位管理LocationClientOption，并设置定位参数，
	 * @return
	 */
	public  LocationClientOption getLocationClientOption(){
		  LocationClientOption option = new LocationClientOption();
	        //打开GPS
	        option.setOpenGps(true);
	        //设置坐标类型
	        option.setCoorType("bd09ll");	
	        
	        //设置网络优先
	  option.setPriority(LocationClientOption.GpsFirst);	
	        //option.setPriority(LocationClientOption.NetWorkFirst);
	        
	        //设置产品线名称
	        option.setProdName("waterSys");
	        
	        //设置定位定时时间
	        option.setScanSpan(500);	
	        
	        
			return option;
	               
	}
	
	
	/**
	 * 得到定位信息对象
	 * @return
	 */
	public BDLocation getBdLocation(){
		
		client.setLocOption(getLocationClientOption());
		client.registerLocationListener(new BDLocationListener() {
			
			@Override
			public void onReceivePoi(BDLocation arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onReceiveLocation(BDLocation arg0) {
				if(arg0!=null){
					location=arg0;
					client.stop();
				}
				
			}
		});
		return location;
		
	}
	
	/**
	 * 得到径维度
	 * @return
	 */
	public Double[] getLoDoubles(){
		BDLocation location=getBdLocation();
		return new Double[]{location.getLatitude(),location.getLongitude()};
		
		
	}
}
